package com.cat.chapter052;

/**
 * @author cat
 * @description https://leetcode.cn/problems/daily-temperatures/
 * @create 2025/7/23 10:52
 * @since JDK17
 */

public class Solution02 {
    static int N = ((int) (1e5 + 10));
    static int[] stack = new int[N];
    public int[] dailyTemperatures(int[] temperatures) {
        int n = temperatures.length, r = 0, cur;
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {   //
            while (r > 0 && temperatures[stack[r - 1]] < temperatures[i]) {
                cur = stack[--r];
                ans[cur] = i;   // 下一个更大的是 i
            }
            stack[r++] = i;
        }
        return ans;
    }
}
